package it.polimi.authentication.web.beans;

import java.util.ArrayList;
import java.util.List;

import it.polimi.authentication.ejb.usermanagement.AddNewHotel;
import it.polimi.authentication.ejb.usermanagement.AddNewMezzo;
import it.polimi.authentication.ejb.usermanagement.ListaHotel;
import it.polimi.authentication.ejb.usermanagement.ListaMezzo;
import it.polimi.authentication.ejb.usermanagement.dto.HotelDTO;
import it.polimi.authentication.ejb.usermanagement.dto.MezzoDTO;

import javax.ejb.EJB;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;

import org.primefaces.context.RequestContext;
import org.primefaces.model.DualListModel;




@ManagedBean (name="RetrieveMezzo")
@SessionScoped
public class RetrieveMezzo {
	
	@EJB
	private ListaMezzo LM;
	
	@EJB
	private AddNewMezzo NM;
	
	private ArrayList<MezzoDTO> MezzoL;
	private ArrayList<String> MezzoLSel;
	
	
	
	public RetrieveMezzo()
	{
	}
	
	public ArrayList<MezzoDTO> getMezzoL() {
		return MezzoL;
	}


	public void setMezzoL(ArrayList<MezzoDTO> mezzoL) {
		MezzoL = mezzoL;
	}


	public ArrayList<String> getMezzoLSel() {
		return MezzoLSel;
	}


	public void setMezzoLSel(ArrayList<String> mezzoLSel) {
		MezzoLSel = mezzoLSel;
	}

	

	public void myMezzo()
	{
		MezzoL = LM.AllMezzoList();
		
	}
	
	
	

	public void CancellaM()
	{
		if (!MezzoLSel.isEmpty()){
			NM.canc(MezzoLSel);

			FacesContext context = FacesContext.getCurrentInstance();  
			context.addMessage(null, new FacesMessage("Mezzo cancellato/i con successo!", "" )); 
			
			FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put("RetrieveMezzo", null);		
			RequestContext context2 = RequestContext.getCurrentInstance();
			context2.update("formM");
		}
		else
		{
			FacesContext context = FacesContext.getCurrentInstance(); 
			context.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR ,"Attenzione!", "Seleziona almeno un mezzo da cancellare!"));
		}
		
	}
	
}
